import request from '@/utils/request';

// 活期定期传参
type BuyProduct = {
    amount?: string;
    signature?: string;
    type?: number;
    id?: number;
    address: string | undefined
}

type Bind = {
    inviter: string // 邀请者、邀请人、上级地址
    signature: `0x${string}` //签名内容
    address: string | undefined
}
// 页面初始化-查询状态
export async function queryInit(query: { inviter: string, address: string | undefined, time: number }) {
    return request('GET', `/api/home/state`, { query: { ...query } });
}

// 绑定
export async function queryBind(body: Bind) {
    return request('POST', '/api/home/bind', { body });
}

// 首页数据
export async function queryProduct(query: { address: string | undefined }) {
    return request('GET', '/api/home/index', { query: { ...query } });
}


// 公告列表
export async function queryNoticeList(query: { address: string | undefined }) {
    return request('GET', '/api/home/notice/list', { query: { ...query } });
}

// 公告详情
export async function queryNoticeDetail(query: { address: string | undefined, id: string }) {
    return request('GET', `/api/home/notice/detail`, { query: { ...query } });
}

// 购买定期
export async function queryBuyFixed(body: BuyProduct) {
    return request('POST', '/api/home/fixed/buy', { body });
}

// 购买活期
export async function queryBuyCurrent(body: BuyProduct) {
    return request('POST', '/api/home/current/buy', { body });
}

// 活期撤回
export async function queryRefundCurrent(body: BuyProduct) {
    return request('POST', '/api/home/current/refund', { body });
}